//
//  ListNode.m
//  AlgorithmDemo
//
//  Created by zxs on 2020/8/5.
//  Copyright © 2020 zxs. All rights reserved.
//

#import "ListNode.h"

@implementation ListNode

// 初始化
- (instancetype)initWithKey:(NSInteger)key andData:(id)data {
    self = [super init];
    if (self) {
        _data = data;
        if (key <= 0) {
            _key = [data hash];
        } else {
            _key = key;
        }
    }
    return self;
}

// 初始化的方便方法，直接用data的hash值作为key
+ (instancetype)nodeWithData:(id)data {
    return [[[self class] alloc] initWithKey:[data hash] andData:data];
}

@end
